/*
* 专业热度top10
* */

(function top10() {
    // 实例化对象
    var myChart = echarts.init(document.querySelector(".p .chart"));
    // 指定配置和数据
    var option = {
        color: ["#00f2f1", "#ed3f35", "#7171C6"],
        tooltip: {
            trigger: "axis",
            axisPointer: {
                // 坐标轴指示器，坐标轴触发有效
                type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: "0%",
            top: "10px",
            right: "0%",
            bottom: "4%",
            containLabel: true
        },
        yAxis: [
            {
                data: [],
                type: "category",
                axisTick: {
                    alignWithLabel: true
                },
                axisLabel: {
                    textStyle: {
                        color: "rgba(255,255,255)",
                        fontSize: "10"
                    }
                },
                axisLine: {
                    show: false
                }
            }
        ],
        xAxis: [
            {
                type: "value",
                axisLabel: {
                    show: true,
                    color: "rgba(255,255,255,.7)",
                    fontSize:"10",
                    formatter: function (value) {
                        if (value >= 1000) {
                            value = value / 10000 + 'w';
                        }
                        return value;
                    },
                },
                axisLine: {
                    lineStyle: {
                        color: "rgba(255,255,255,.1)"
                        // width: 1,
                        // type: "solid"
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: "rgba(255,255,255,.1)"
                    }
                }
            }
        ],
        series: [{
            type: 'bar',
            barWidth: "35%",
            smooth: true,
            itemStyle: {
                color: "#1089E7",
                barBorderRadius: 6
            },
            name: "人气值",
            data: []
        }]

    };
    $.ajax({
        url: 'http://localhost:8080/heat/data1',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            var name = [];
            var popularity = [];
            // var results = []
            for (let i = 0; i < res.length; i++) {
                name[i] = res[i]["name"]
                popularity[i] = res[i]["popularity"]

                // results.push({name: time[i], value: grade1[i]})
            }
            console.log(name);
            console.log(popularity);
            option.yAxis[0].data = name;
            option.series[0].data = popularity;
            myChart.setOption(option);
        }
    });


    // option.xAxis[0].data = time;
    // option.series[0].data = grade;
    // // 把配置给实例对象
    myChart.setOption(option);
    window.addEventListener("resize", function () {
        myChart.resize();
    })
}) ();

/*
* 授予学位类型
* */
(function selectDegree() {
    // 实例化对象
    var myChart = echarts.init(document.querySelector(".p1 .chart"));
    // 指定配置和数据
   var option = {
       title: {
           left: 'center'
       },
       tooltip: {
           trigger: 'item'
       },
       legend: {
           orient: 'vertical',
           left: 'left'
       },
       series: [
           {

               type: 'pie',
               radius: '50%',
               data: [
               ],
               emphasis: {
                   itemStyle: {
                       shadowBlur: 10,
                       shadowOffsetX: 0,
                       shadowColor: 'rgba(0, 0, 0, 0.5)'
                   }
               }
           }
       ]
   };
    $.ajax({
        url: 'http://localhost:8080/heat/selectDegree',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            var name = [];
            var time = [];
            var results = []
            for (let i = 0; i < res.length; i++) {
                name[i] = res[i]["degree"].split("：")[1]
                time[i] = res[i]["counts"]

                results.push({name: name[i], value: time[i]})

            }
            console.log(results);
            // console.log(grade1);
            option.series[0].data = results;
            myChart.setOption(option);

        }
    });
    // option.xAxis[0].data = time;
    // option.series[0].data = grade;
    // // 把配置给实例对象
    // myChart.setOption(option);
    window.addEventListener("resize", function () {
        myChart.resize();
    })
}) ();


/*
* 修业年限
* */
(function selectYear() {
    // 实例化对象
    var myChart = echarts.init(document.querySelector(".year .chart"));
    // 指定配置和数据
    var option = {
        color: ["#00f2f1", "#ed3f35", "#7171C6"],
        tooltip: {
            trigger: "axis",
            axisPointer: {
                // 坐标轴指示器，坐标轴触发有效
                type: "shadow" // 默认为直线，可选为：'line' | 'shadow'
            }
        },
        grid: {
            left: "0%",
            top: "10px",
            right: "0%",
            bottom: "4%",
            containLabel: true
        },
        xAxis: [
            {
                type: "category",
                data: [],
                axisTick: {
                    alignWithLabel: true
                },
                axisLabel: {
                    textStyle: {
                        color: "rgba(255,255,255,.6)",
                        fontSize: "10"
                    }
                },
                axisLine: {
                    show: false
                }
            }
        ],
        yAxis: [
            {
                type: "value",
                axisLabel: {
                    textStyle: {
                        color: "rgba(255,255,255,.6)",
                        fontSize: "10"
                    }
                },
                axisLine: {
                    lineStyle: {
                        color: "rgba(255,255,255,.1)"
                        // width: 1,
                        // type: "solid"
                    }
                },
                splitLine: {
                    lineStyle: {
                        color: "rgba(255,255,255,.1)"
                    }
                }
            }
        ],
        series: [{
            type: 'bar',
            barWidth: "35%",
            smooth: true,
            itemStyle: {
                color: "#1089E7",
                barBorderRadius: 6
            },
            data: []//[260,406,529],
        }
        ]

    };
    $.ajax({
        url: 'http://localhost:8080/heat/selectYear',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            var name = [];
            var times = [];
            var results = []
            for (let i = 0; i < res.length; i++) {
                name[i] = res[i]["year"].split("：")[1]
                times[i] = res[i]["counts"]

                results.push({name: name[i], value: times[i]})
            }
            console.log(name);
            console.log(results);
            option.xAxis[0].data = name;
            option.series[0].data = times;
            myChart.setOption(option);

        }
    });
    // option.xAxis[0].data = time;
    // option.series[0].data = grade;
    // // 把配置给实例对象
    // myChart.setOption(option);
    window.addEventListener("resize", function () {
        myChart.resize();
    })
}) ();




/*
* 既有四年的专业也有五年的专业
* */
(function selectDegree() {
    // 实例化对象
    var myChart = echarts.init(document.querySelector(".p2 .chart"));
    // 指定配置和数据
    var option = {
        tooltip: {
            trigger: 'item'
        },
        series: [
            {
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                    borderRadius: 10,
                    borderColor: '#fff',
                    borderWidth: 2
                },
                emphasis: {
                    label: {
                        show: true,
                        fontSize: '40',
                        fontWeight: 'bold'
                    }
                },
                labelLine: {
                    show: false
                },
                data: [
                ]
            }
        ]
    };
    $.ajax({
        url: 'http://localhost:8080/heat/selectNoYear',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            var name = [];
            var time = [];
            var results = []
            for (let i = 0; i < res.length; i++) {
                name[i] = res[i]["NAME"]
                time[i] = res[i]["counts"]

                results.push({name: name[i], value: time[i]})
            }
            // console.log(time);
            // console.log(grade1);
            // option.xAxis.data = time;
            option.series[0].data = results;
            myChart.setOption(option);

        }
    });
    // option.xAxis[0].data = time;
    // option.series[0].data = grade;
    // // 把配置给实例对象
    // myChart.setOption(option);
    window.addEventListener("resize", function () {
        myChart.resize();
    })
}) ();


/*
* top10男女比例
* */
(function nvTop10() {

    $.ajax({
        url: 'http://localhost:8080/heat/data1',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            var name = [];
            var r = [];
            var results = []
            for (let i = 0; i < res.length; i++) {
                name[i]= res[i]["name"]
                r[i] = res[i]['ratio']
                $('#No'+i).text(name[i]+r[i]);
            }
        }
    });

}) ();

/*
* 模板
* */
/*(function selectDegree() {
    // 实例化对象
    var myChart = echarts.init(document.querySelector(".selectDegree .chart"));
    // 指定配置和数据
   var  option
    $.ajax({
        url: 'http://localhost:8080/text1',
        type: 'get',
        dataType: 'json',
        success: function (res) {
            var time = [];
            var grade1 = [];
            // var results = []
            for (let i = 0; i < res.length; i++) {
                time[i] = res[i]["time"]
                grade1[i] = res[i]["grade"]

                // results.push({name: time[i], value: grade1[i]})
            }
            console.log(time);
            console.log(grade1);
            option.xAxis.data = time;
            option.series[0].data = grade1;

        }
    });
    // option.xAxis[0].data = time;
    // option.series[0].data = grade;
    // // 把配置给实例对象
    // myChart.setOption(option);
    window.addEventListener("resize", function () {
        myChart.resize();
    })
}) ();*/



